package com.cloud.config.mybatis.base.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;

/**
 * 公共实体父类
 * @author wangjian
 * @version 1.0.0
 * @create 2020年10月15日16:37
 */
@Data
@ApiModel(value = "基础实体对象", description = "基础实体对象")
public class BaseEntity extends Model {

    @ApiModelProperty(value = "主键")
    @TableId(type= IdType.AUTO)
    private Long id;

    @ApiModelProperty(value = "创建人id")
    @TableField(value = "created_by",fill = FieldFill.INSERT)
    private Long createdBy;

    @ApiModelProperty(value = "创建时间")
    @TableField(value = "created_time",fill = FieldFill.INSERT)
    private Date createdTime;

    @ApiModelProperty(value = "更新人id")
    @TableField(value = "updated_by",fill = FieldFill.INSERT_UPDATE)
    private Long updatedBy;

    @ApiModelProperty(value = "更新时间")
    @TableField(value = "updated_time",fill = FieldFill.INSERT_UPDATE)
    private Date updatedTime;

    @ApiModelProperty(value = "版本号")
    @Version
    @TableField(value = "version", fill = FieldFill.INSERT)
    private Integer version;

    @ApiModelProperty(value = "是否已删除")
    @TableLogic
    @TableField(value = "is_deleted",fill = FieldFill.INSERT)
    private Boolean deleted;

    @Override
    protected Serializable pkVal() {
        return null;
    }

    /**
     * 添加时首次插入操作人信息
     * @param operationId   操作人id
     */
    public void firstCreateBy(Long operationId){
        setCreatedBy(operationId);
        setUpdatedBy(operationId);
    }

}
